package 语雀题目21至55;

import java.util.Scanner;

/**
 * ClassName: 输出指定位数的水仙花数
 * Package: 语雀21至40
 * Description:
 *
 * @Author fjorid
 * @Create 2025/1/6 15:35
 * @Version 1.0
 */
public class 输出指定位数的水仙花数22 {
    public static void main(String[] args) {
        Scanner sacn = new Scanner(System.in);
        System.out.println("请输入要计算的水仙花数的位数");
        int digit = sacn.nextInt();
        int lowerBound,previousBound;
        int temo=1,sum=0;
        lowerBound = previousBound = 1;
        //根据位数确定范围
        for (int i = 1; i <= digit; i++) {
            previousBound *= 10;
        }
        previousBound = previousBound-1;//求n位整数的最大值
        for (int i = 1; i <= digit-1; i++) {
            lowerBound *= 10;//求n位整数的最小值
        }
        for (int i = lowerBound; i <= previousBound; i++) {//判断是否位水仙花数，并输出
            int a = i;
            while (a>0){
              temo = a%10;
              int b = temo;
              for (int j = 1; j <= digit-1; j++) {
                  temo *= b;
              }
                a = a/10;
              sum += temo;

          }
          if(sum == i){
              System.out.println(i+"是水仙花数");
          }
        sum = 0;
          temo = 1;
        }
    }
}




